package com.cloudptt.api.product.func.media.device;

import android.content.Intent;
import android.content.IntentFilter;

import com.cloudptt.api.comm.Const;
import com.cloudptt.api.product.func.media.EventListener;
import com.cloudptt.api.product.log.Log;

public class NtF3 implements IDeviceKey {
	public final static String THIS_FILE = "NtF3";
	private static final String BRAND = "SPRD";
	private static final String DEVICE = "sp9820e_1h10ll";
	private static final String MODEL = "NT-F3";

	private IntentFilter mFilter;
	 private final static String ACTION_PTT_DOWN = "flyscale.hotkey.ptt.down";
	private final static String ACTION_PTT_UP = "flyscale.hotkey.ptt.up";

	private final static String ACTION_SOS_DOWN = "flyscale.hotkey.m2.down";
	private final static String ACTION_SOS_UP = "flyscale.hotkey.m2.up";

	private long pttOnTimer =  0;

	public NtF3(){
		
	}
	
	public static boolean isThisDev(String brand,String device,String model){
		Log.d(THIS_FILE, "isThisDev 1 BRAND = " + brand + " DEVICE = " + device  + " MODEL = " + model);
		Log.d(THIS_FILE, "isThisDev 2 BRAND = " + BRAND + " DEVICE = " + DEVICE  + " MODEL = " + MODEL);
		if(brand == null
				|| device == null
				|| model == null){
			return false;
		}
		else if(BRAND.equals(brand)
				&& DEVICE.equals(device)
				&& MODEL.equals(model)){
			return true;
		}
		return false;
	}

	@Override
	public IntentFilter getBstIntentFilter() {
		Log.d(THIS_FILE, "getBstIntentFilter");
		mFilter = new IntentFilter();
		mFilter.addAction(ACTION_PTT_DOWN);/**蓝牙指环PTT**/
		mFilter.addAction(ACTION_PTT_UP);
		mFilter.addAction(ACTION_SOS_DOWN);
		mFilter.addAction(ACTION_SOS_UP);
		
		return mFilter;
	}
	
	@Override
	public void procBst(Intent intent, EventListener listener) {
		String action = intent.getAction();
		Log.d(THIS_FILE, " procBst action = " + action);
		if(action.equals(ACTION_PTT_DOWN)){
			if (listener != null) {
				listener.onPtt(Const.MSG_TALK_ON, false, true);
			}
		}
		else if(action.equals(ACTION_PTT_UP)){
			if (listener != null) {
				listener.onPtt(Const.MSG_TALK_OFF, false, true);
			}
		}
		else if(action.equals(ACTION_SOS_DOWN)){
			pttOnTimer = System.currentTimeMillis();
		}
		else if(action.equals(ACTION_SOS_UP)){
			long val = System.currentTimeMillis();
			boolean isLongPress = (val - pttOnTimer) > 2000;
			if (listener != null) {
				listener.onSOS(isLongPress);
			}
		}
	}

}
